#pragma once

#include <map>
#include <vector>
#include <string>
#include "TestSecuTradeApi.hpp"

//typedef std::vector<CHS> REALTIMEFIELD;
typedef std::map<std::string, CHSSecuOrderField> ENTRUST_MAP;
typedef std::map<std::string, CHSSecuOrderField>::iterator ENTRUST_MAP_ITER;
//typedef std::map<std::string, REALTIMEFIELD> TRADE_MAP;
//typedef std::map<std::string, REALTIMEFIELD>::iterator TRADE_MAP_ITER;
class TestSecuTradeSpi :public CHSSecuTradeSpi
{
private:
	CHSSecuTradeApi * lpUserApi;
	volatile bool bStopDealBusiness;//是否停止处理业务线程
public:
	int Current_Entrust;
	int iRequestId;//请求ID
	int Rsp_times;
	int Req_times;
	int t;
	ENTRUST_MAP EntrustListMap;
	//TRADE_MAP TradeListMap;
	TestSecuTradeSpi(CHSSecuTradeApi* lpObj)
	{
		lpUserApi = lpObj;
		bStopDealBusiness = false;
		iRequestId = 0;
		Current_Entrust = 0;
		Rsp_times = 0;
		Req_times = 0;
		t = 0;
	}
	void Start();
	static void* DealBusiness(void* lpvoid);
	void OnFrontConnected();
	void OnFrontDisconnected(int nResult); 
	bool IsErrorRspInfo(CHSSecuRspInfoField * pRspInfo);
	void OnRspAuthenticate(CHSSecuRspAuthenticateField *pRspAuthenticate, CHSSecuRspInfoField * pRspInfo, int nRequestID, bool bIsLast);
	void OnRspUserLogin(CHSSecuRspUserLoginField * pRspUserLogin, CHSSecuRspInfoField * pRspInfo, int nRequestID, bool bIsLast);
	//void OnRspUserPasswordUpdate(CHSSecuRspUserPasswordUpdateField * pRspUserPasswordUpdate, CHSSecuRspInfoField * pRspInfo, int nRequestID, bool bIsLast);
	void OnRspOrderInsert(CHSSecuRspOrderInsertField * pRspOrderInsert, CHSSecuRspInfoField * pRspInfo, int nRequestID, bool bIsLast);
	//void OnRtnRealtime(CHSApiEntrustPushField * pRtnTrade);
	//void OnRtnEntrust(CHSApiEntrustPushField * pRtnOrder);
	//void UpdateEntrust(CHSApiEntrustPushField * pRtnOrder);
	//void UpdateRealtime(CHSApiEntrustPushField * pRtnTrade);
	virtual void OnRtnOrder(CHSSecuOrderField *pRtnOrder);
	virtual void OnRtnTrade(CHSSecuTradeField *pRtnTrade);
	void OnRspOrderAction(CHSSecuRspOrderActionField * pRspOrderAction, CHSSecuRspInfoField * pRspInfo, int nRequestID, bool bIsLast);
	//void OnRspQryTrade(CHSSecuTradeField *pRspQryTrade, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
	//void OnRspQryOrder(CHSSecuOrderField *pRspQryOrder, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
	//void OnRspQryFund(CHSSecuRspQryFundField *pRspQryTradingAccount, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
	void OnRspQryHold(CHSSecuRspQryHoldField *pRspQryPosition, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
	/// Description:当客户端与交易后台通信连接异常时，该方法被调用。
	//void OnRspQryEquity(CHSSecuRspQryEquityField *pRspQryEquity, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
	//void OnRspQryStkcode(CHSSecuRspQryStkcodeField *pRspQryStkcode, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
	//void OnRspQryEtfcode(CHSSecuRspQryEtfcodeField *pRspQryEtfcode, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
	//void OnRspQryEtfcomponent(CHSSecuRspQryEtfcomponentField *pRspQryEtfcomponent, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
	//void OnRspQryCreditCollateral(CHSSecuReqQryCreditCollateralField *pRspQryCreditCollateral, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
	//void OnRspQryCreditUnderlying(CHSSecuRspQryCreditUnderlyingField *pRspQryCreditUnderlying, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
	//void OnRspQryEnfinFund(CHSSecuRspQryEnfinFundField *pRspQryEnfinFund, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
	//void OnRspQryEnsloStock(CHSSecuRspQryEnsloStockField *pRspQryEnsloStock, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
	//void OnRspQryCreditRate(CHSSecuRspQryCreditRateField *pRspQryCreditRate, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
	//void OnRspQryCreditAsset(CHSSecuRspQryCreditAssetField *pRspQryCreditAsset, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
	//void OnRspQryPendfare(CHSSecuRspQryPendfareField *pRspQryPendfare, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
	//void OnRspQryCompact(CHSSecuRspQryCompactField *pRspQryCompact, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
	//void OnRspQryImpawnDetail(CHSSecuRspQryImpawnDetailField *pRspQryImpawnDetail, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
	//void OnRspCashRepay(CHSSecuRspCashRepayField *pRspCashRepay, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
	//void OnRspUserFundTransfer(CHSSecuRspUserFundTransferField *pRspUserFundTransfer, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
	//void OnRspUserStockTransfer(CHSSecuRspUserStockTransferField *pRspUserStockTransfer, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
	//void OnRspQryTrusteeRatio(CHSSecuRspQryTrusteeRatioField *pRspQryTrusteeRatio, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
	//void OnRspQryBondImpawnConc(CHSSecuRspQryBondImpawnConcField *pRspQryBondImpawnConc, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
	void OnRspQryBankAccount(CHSSecuRspQryBankAccountField *pRspBankAccount, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
	/// Others     :通过GetApierror_info(nResult)获取详细错误信息。

};
